<template>
<div class="forget_container">
    <div class="forget_box">
      <el-form :model="forgetForum" status-icon ref="ruleForm" label-width="100px" class="demo-ruleForm">
        <el-form-item label="用户名">
          <el-input v-model="forgetForum.username" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item
          prop="email"
          label="邮箱"
          :rules="[
            { required: true, message: '请输入邮箱地址', trigger: 'blur' },
            { type: 'email', message: '请输入正确的邮箱地址', trigger: ['blur', 'change'] }
          ]"
        >
          <el-input v-model="forgetForum.email"></el-input>
        </el-form-item>
        <el-form-item label="验证码">
          <el-input v-model="forgetForum.code"></el-input>
        </el-form-item>
        <el-form-item class="btns">
          <el-button type="primary" @click="getMailCode">获取验证码</el-button>
          <el-button type="success" @click="resetPwd">重置密码</el-button>
          <el-button type="info" @click="back">返回</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
export default {
  data () {
    return {
      forgetForum: {
        username: '',
        code: '',
        id: '',
        email: ''
      }
    }
  },
  methods: {
    back () {
      this.$router.go(-1)
    },
    getMailCode () {
      this.$axios.get('user/getMailCode', {
        params: {
          username: this.forgetForum.username,
          email: this.forgetForum.email
        }
      }).then(response => {
        this.forgetForum.id = response.data.data
      }).catch(error => {
        console.log(error)
      })
    },
    resetPwd () {
      this.$axios.get('user/reset', {
        params: {
          username: this.forgetForum.username,
          code: this.forgetForum.code,
          id: this.forgetForum.id
        }
      }).then(response => {
        this.$message.success(response.data.msg)
      }).catch(error => {
        console.log(error)
      })
    }
  }
}
</script>

<style lang="less" scoped>
.forget_container{
  height: 100%;
  background-image: url('../assets/University.png');
  background-repeat: no-repeat;
  background-size:100% 100%;
}
.forget_box{
    width: 450px;
    height: 270px;
    background-color: #fff;
    border-radius: 3px;
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%,-50%);
}
.btns{
    display: flex;
    justify-content: flex-end;
}
.demo-ruleForm{
    position: absolute;
    width: 100%;
    top: 20px;
    padding: 0 20px;
    box-sizing: border-box;
}
</style>
